//
// Created by Administrator on 2023/8/3.
//


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <set>
#include <regex>

using namespace std;

class Solution {
public:
    vector<int> distinctDifferenceArray(vector<int> &nums) {
        unordered_set<int> set;
        vector<int> leftCount(nums.size(), 0);
        // 从左向右，左边出现的不同数字的个数
        for (int i = 0; i < nums.size(); i++) {
            set.insert(nums[i]);
            leftCount[i] = set.size();
        }
        // 从右向左，右边出现的不同数字的个数
        // 最右边是0
        set.clear();
        vector<int> rightCount(nums.size(), 0);
        for (int i = nums.size() - 1; i > 0; i--) {
            set.insert(nums[i]);
            rightCount[i-1] = set.size();
        }
        vector<int> result(nums.size(), 0);
        for (int i = 0; i < nums.size(); i++) {
            result[i] = leftCount[i] - rightCount[i];
        }
        return result;

    }
};

int main() {
    Solution solution;
    vector<int> nums = {3,2,3,4,2};
    vector<int> result = solution.distinctDifferenceArray(nums);
    for (int i: result) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}